<template>
  <div class="list">
    <div>
      <el-form size="small" :inline="true" :model="whereData" class="search-from">
        <el-form-item>
          <el-input @keyup.enter.native="init()" clearable v-model="whereData.batch_number" placeholder="批次号"></el-input>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            style="width: 320px"
            v-model="whereData.created_at"
            type="daterange"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="付款时间（开始）"
            end-placeholder="付款时间（结束）"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="init()">查询</el-button>
          <!-- <el-button type="success" @click="exportData('结算记录')">下载</el-button> -->
        </el-form-item>
      </el-form>
    </div>
    <div class="section">
      <el-table
        :data="tableData"
        v-loading="isLoading"
        style="width: 100%">
        <el-table-column
          align="center"
          prop="id"
          sortable="custom"
          label="ID">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="batch_number"
          label="批次号">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="import_num"
          label="笔数">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="pay_time"
          label="付款时间">
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="pay_money"
          label="支付总额">
          <template slot-scope="scope">
            <span>{{scope.row.pay_money | numFilter}}</span>
          </template>
        </el-table-column>
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="settle_money"
          label="实付总额">
          <template slot-scope="scope">
            <span>{{scope.row.settle_money | numFilter}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="address"
          label="支付方式">
        </el-table-column> -->
        <el-table-column
          sortable="custom"
          align="center"
          show-overflow-tooltip
          prop="pay_status"
          label="打款状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.pay_status === -1" size="small" type="warning">打款失败</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 1" size="small" type="info">等待打款</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 2" size="small" type="">打款中</el-tag>
            <el-tag v-else-if="scope.row.pay_status === 3" size="small" type="danger">部分打款</el-tag>
            <el-tag v-else size="small" type="success">打款成功</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          show-overflow-tooltip
          prop="address"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="goDetail(scope.row)" size="mini" type="primary">查看</el-button>
            <!-- <el-button @click="goPayment(scope.row)" size="mini" type="primary">打款</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </div>
  </div>
</template>
<script>
export default {
  name: 'list',
  data() {
    return {
      whereData: {
        batch_number: '',
        created_at: '',
      },
      isLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      tableData: [],
      daterange: ''
    }
  },
  mounted() {
    this.init()
  },
  filters: {
    // 截取当前数据到小数点后两位
    numFilter(value) {
      const realVal = parseFloat(value).toFixed(2);
      return realVal;
    }
  },
  methods: {
    init() {
      this.$http.get('/company/payment/list',{
        'batch_number': this.whereData.batch_number,
        'created_at': this.whereData.created_at,
        'page': this.pageIndex,
        'limit': this.pageSize
      }).then(res => {
        if (res.code === 0) {
          console.log(res)
          this.tableData = res.page.list
          this.totalPage = res.page.totalCount
          this.amountData = res.amount
        }
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.init()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.init()
    },
    goDetail(row) {
      this.$router.push('/company/deal/settlement/detail?id=' + row.id)
    }
  }
}
</script>
